package org.fjsei.yewu.job.jobs;

import org.fjsei.yewu.job.util.Constant;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.Date;

@Slf4j
public class RupayCardJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        long startDate = System.currentTimeMillis();
        log.info("Job with JobName {}, GroupName {} is started at {}", jobExecutionContext.getJobDetail().getKey().getName(), jobExecutionContext.getJobDetail().getKey().getGroup(), Constant.SIMPLE_DATE_FORMAT.format(new Date()));
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            log.info("Job with JobName {}, GroupName {} is completed at {} and time taken is {} second", jobExecutionContext.getJobDetail().getKey().getName(), jobExecutionContext.getJobDetail().getKey().getGroup(), Constant.SIMPLE_DATE_FORMAT.format(new Date()), (System.currentTimeMillis() - startDate) / 1000);
        }
    }
}